<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/bluetooth/resources/bluetooth-test.js"></script>
<script src="/bluetooth/resources/bluetooth-fake-devices.js"></script>
<script src="/bluetooth/resources/bluetooth-scanning-helpers.js"></script>
<script>
'use strict';
const test_desc = 'Device address have the same device id.';

bluetooth_test(async (t) => {
  const fake_central =
      await navigator.bluetooth.test.simulateCentral({state: 'powered-on'});

  await callWithTrustedClick(async () => {
    await navigator.bluetooth.requestLEScan({acceptAllAdvertisements: true});
  });

  const eventWatcher =
      new EventWatcher(t, navigator.bluetooth, ['advertisementreceived']);

  let scan = {
    deviceAddress: '09:09:09:09:09:09',
    rssi: 100,
    scanRecord: {
      txPower: 20,
    },
  };

  let actual_device_id;

  fake_central.simulateAdvertisementReceived(scan);
  await eventWatcher.wait_for(['advertisementreceived']).then(e => {
    actual_device_id = e.device.id;
  });

  fake_central.simulateAdvertisementReceived(scan);
  await eventWatcher.wait_for(['advertisementreceived']).then(e => {
    assert_equals(e.device.id, actual_device_id);
  });

  scan.deviceAddress = 'FF:FF:FF:FF:FF:FF'
  fake_central.simulateAdvertisementReceived(scan);
  await eventWatcher.wait_for(['advertisementreceived']).then(e => {
    assert_not_equals(e.device.id, actual_device_id);
  });
}, test_desc);
</script>
